package com.xinghou.platform.server.api.controller;

import com.xinghou.platform.entity.req.ShareInfoReq;
import com.xinghou.platform.entity.resp.ShareInfoListResp;
import com.xinghou.platform.entity.resp.ShareInfoResp;
import com.xinghou.platform.server.api.bussiness.ShareInfoBusinessService;
import com.xinghou.platform.server.api.bussiness.ShopInfoBusinessService;
import com.xinghou.platform.util.StringUtils;
import com.xinghou.platform.util.exception.DBExceptionEnums;
import com.xinghou.platform.util.exception.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分享信息处理
 * @author xuzhen
 *
 */
@Controller
public class GetShareInfoForShopController extends BaseControl {

	
	@Resource
	private ShareInfoBusinessService shareInfoBusinessService;
	
	@Resource
	private ShopInfoBusinessService shopInfoBusinessService;
	
	/**
	 * 分享信息列表(门店)
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/findSharelistShop", method = {RequestMethod.POST})
	public String findSharelistShop(@RequestBody ShareInfoReq shareInfoReq,
			HttpServletRequest request, HttpServletResponse response){
		ShareInfoListResp shareInfoListResp = new ShareInfoListResp();
		try {
			if(StringUtils.isBlank(shareInfoReq.getUserid())){
				throw new ServiceException(DBExceptionEnums.USER_IS_NULL);
			}else if(StringUtils.isBlank(shareInfoReq.getShopid())){
				throw new ServiceException(DBExceptionEnums.SHOPID_IS_NULL);
			}
				List<ShareInfoResp> shareInfoRespList = shareInfoBusinessService.getSharedCardForShoplist(shareInfoReq);
				shareInfoListResp.setDatalist(shareInfoRespList);
				if(shareInfoRespList.size()>0){
					shareInfoListResp.setFromno(shareInfoRespList.get(shareInfoRespList.size()-1).getFromno());
				}else{
					shareInfoListResp.setFromno(shareInfoReq.getFromno());
				}
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(DBExceptionEnums.SERVER_INTEERFACE_ERROR);
		}

		return response(shareInfoListResp);
	}
	

	/*public String getReqjson() {
		return reqjson;
	}

	public void setReqjson(String reqjson) {
		this.reqjson = reqjson;
	}

	public String getRepjson() {
		return repjson;
	}

	public void setRepjson(String repjson) {
		this.repjson = repjson;
	}

	public ShareInfoListResp getShareInfoListResp() {
		return shareInfoListResp;
	}

	public void setShareInfoListResp(ShareInfoListResp shareInfoListResp) {
		this.shareInfoListResp = shareInfoListResp;
	}

	public ShareInfoPhotoResp getShareInfoPhotoResp() {
		return shareInfoPhotoResp;
	}

	public void setShareInfoPhotoResp(ShareInfoPhotoResp shareInfoPhotoResp) {
		this.shareInfoPhotoResp = shareInfoPhotoResp;
	}
	*/
	
}
